<?php

namespace App\Shop\Controllers;

use App\Admin\Repositories\OrderCommission;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OrderCommissionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new OrderCommission(), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->disableRowSelector();
            $grid->disableActions();
            $admin = Admin::user();
            $isShop = $admin->isAdministrator();
            if ($isShop){
                $shop_id = $admin->id;
            }else{
                $shop_id = $admin->shop_id;
            }
            $grid->model()->where("shop_id", $shop_id);
            $grid->column('order_id');
            $grid->column('type',"订单类型")->using(['洗车订单','商城订单','洗车卡订单'])->label(['info','success']);
            $grid->column('amount','营业收入');
//            $grid->column('money','分成金额(营业收入-取消退款)');
            $grid->column('platform_money','平台分成');
            $grid->column('agent_money','代理商分成');
            $grid->column('top_money','上级用户分成');
            $grid->column('top_top_money','上级级用户分成');
            $grid->column('shop_money','门店分成');
            $grid->column('worker_money','员工分成');
            $grid->column('settle_time','结算入账时间');
            $grid->column('is_settle','是否结算')->radio(['未结算','已结算'],true)->label(['default','primary']);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand(true);
                $filter->like('order_id')->width(3);
                $filter->equal('type','订单类型')->select(['洗车订单','商城订单','洗车卡订单'])->width(3);
                $filter->equal('is_settle','是否结算')->select(['未结算','已结算'])->width(3);
                $filter->between('settle_time','结算入账时间')->date()->width(3);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new OrderCommission(), function (Show $show) {
            $show->field('id');
            $show->field('type');
            $show->field('order_id');
            $show->field('service_id');
            $show->field('service_name');
            $show->field('amount');
            $show->field('money');
            $show->field('province_id');
            $show->field('city_id');
            $show->field('district_id');
            $show->field('shop_id');
            $show->field('shop_rate');
            $show->field('shop_money');
            $show->field('worker_id');
            $show->field('worker_rate');
            $show->field('worker_money');
            $show->field('agent_city_id');
            $show->field('agent_city_rate');
            $show->field('agent_city_money');
            $show->field('agent_district_id');
            $show->field('agent_district_rate');
            $show->field('agent_district_money');
            $show->field('settle_time');
            $show->field('is_settle');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new OrderCommission(), function (Form $form) {
            $form->display('id');
            $form->text('type');
            $form->text('order_id');
            $form->text('service_id');
            $form->text('service_name');
            $form->text('amount');
            $form->text('money');
            $form->text('province_id');
            $form->text('city_id');
            $form->text('district_id');
            $form->text('shop_id');
            $form->text('shop_rate');
            $form->text('shop_money');
            $form->text('worker_id');
            $form->text('worker_rate');
            $form->text('worker_money');
            $form->text('agent_city_id');
            $form->text('agent_city_rate');
            $form->text('agent_city_money');
            $form->text('agent_district_id');
            $form->text('agent_district_rate');
            $form->text('agent_district_money');
            $form->text('settle_time');
            $form->text('is_settle');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
